<?php

namespace App\Admin\Controllers;

use App\Services\CustomerBuService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * C业务管理
 *
 * @property CustomerBuService $service
 */
class CustomerBuController extends AdminController
{
	protected string $serviceName = CustomerBuService::class;

	public function index()
	{
			$fcustomer_id = request()->input('fcustomer_id');
			if ($this->actionOfGetData()) {
				return $this->service->getData($fcustomer_id);
			}


		// 没有携带 _action 参数的请求, 返回列表结构
		return $this->response()->success($this->list()); // 这里调用了 list 方法
	}

	public function list()
	{
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('idcnode.idc_name', 'IDC机房'),
				amis()->TableColumn('fcustomer.short_name', '客户'),
				amis()->TableColumn('name', '业务期次'),
				amis()->TableColumn('bandwidth', '出口带宽G'),
				amis()->TableColumn('billing_type', '计费方式'),
				amis()->TableColumn('charge_cabinet', '收费机柜'),
				amis()->TableColumn('guarantee_bandwidth', '保底'),
				amis()->TableColumn('sign_company.company_name', '签约公司'),
				
				amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
				$this->rowActions('dialog')
			]);

		return $this->baseList($crud);
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
			amis()->TextControl('name', '业务期次'),
			amis()->SelectControl('fcustomer_id', '选择客户')
				->source('/fcustomer?_action=getData')
				->searchable(true)
				->labelField('short_name')
				->valueField('id'),
			amis()->SelectControl('sign_company', '签约公司')
				->source('/company?_action=getData')
				->searchable(true)
				->labelField('company_name')
				->valueField('id'),
			amis()->SelectControl('idcnode_id', 'IDC机房')
				->searchable(true)
				->source('/idcnode?idc_belong=${type_id}&_action=getData')
				->labelField('idc_name')
				->valueField('id'),
			amis()->GroupControl()
				->body([
					amis()->SelectControl('billing_type', '计费方式')
				->options([
					['label' => '月95计费', 'value' => '月95计费'], 
					['label' => '包端口', 'value' => '包端口'], 
					['label' => '日峰月均', 'value' => '日峰月均'],
					['label' => '日95', 'value' => '日95'],
					['label' => '日95月均', 'value' => '日95月均']
					]),
				amis()->TextControl('charge_cabinet', '收费机柜'),
			]),
			amis()->GroupControl()
				->body([
					amis()->NumberControl('bandwidth', '出口带宽G'),
					amis()->NumberControl('guarantee_bandwidth', '保底G'),
				]),
			
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('editor_uid', '编辑人UID')->static(),
			amis()->TextControl('fcustomer_id', '上游客户')->static(),
			amis()->TextControl('is_delete', '是否删除：0-未删除 1-已删除')->static(),
			amis()->TextControl('name', '业务名称')->static(),
			amis()->TextControl('operator_uid', '操作人UID')->static(),
			amis()->TextControl('sign_company', '签约公司')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}


}